

--模拟弹道
local buff = ac.buff['弹道设置']
buff.model1 = [[Abilities\Weapons\Arrow\ArrowMissile.mdl]]
buff.model1 = [[Abilities\Spells\Items\WandOfNeutralization\NeutralizationMissile.mdl]]
buff.cover_type = 1
buff.cover_max = 1
buff.keep = true

function buff:on_add()
    local hero = self.owner
    self.missile_art = hero.missile_art or self.model1
    self:gc(hero:event ' 单位-更换英雄'(function()
        self.missile_art = hero.missile_art or self.model1
    end))
    self:gc(hero:event '单位-攻击出手'(function(_,source,target)
        local start = source:get_launch_point()
        local count1 = math.floor(hero:get('多重数量'))
        local count2 = 0

        local list = {}
        if count1>0 then
            local area = math.min(hero:get('攻击距离')+100,1200)
            list = ac.selector('unit'):range(hero,area):enemy(hero):is_not(target):near(target):get(count1)
        end
        list[#list + 1] = target
        for _,unit in ipairs(list) do
            local temp = {
                damage_count = 0,
                damage_max = count2,
                target = target,
            }
            self:catapult(temp,start,unit)
        end
        
        source:notify('单位-攻击出手后',source,target)

        return true
    end))
end

--[弹射和多重处理]
function buff:catapult(temp,start,dest,params)
    local hero = self.owner
    temp[dest.handle] = true
    start:launch_missile(dest,self.missile_art,1200,0,function(mvr)
        local atk = hero:get('攻击')
        if temp.damage_count==0 then
            if temp.target==dest then
                hero:create_damage(dest, atk, '普攻')
            else
                --hero:create_damage(dest, atk * hero:get('多重伤害')*0.01)
                hero:create_damage(dest, atk)
            end
        else
            hero:create_damage(dest, atk * hero:get('弹射伤害')*0.01)
        end
        if temp.damage_count < temp.damage_max then
            temp.damage_count = temp.damage_count + 1
            local point = dest:get_launch_point()
            local target = ac.selector('unit'):range(dest,600):is_not(dest):enemy(hero):sorter(function(a,b)
                if temp[a.handle] and temp[b.handle]==nil then
                    return false
                end
                if temp[a.handle]==nil and temp[b.handle] then
                    return true
                end
                local r1 = a:get_point() * point
                local r2 = b:get_point() * point
                return r1 < r2
            end):first()
            if target then
                mvr.need_remove_mover = false
                self:catapult(temp,point,target,{mover = mvr.mover})
            end
        end
    end,params)
end


ac.game:event '玩家-选择英雄完毕'(function(_,player,hero)
    hero:add_buff '弹道设置'{}
end)